<?php

function copyFile ($file, $filename, $media_type, $next_id)
{
  $fname_arr = explode('.', $filename);
  $file_ext = $fname_arr[count($fname_arr) - 1];

  $url = strtolower($media_type)."/".$next_id.'.'.$file_ext;

  if (file_exists($url)) {
    echo $url." already exists";
  } else {
    move_uploaded_file($file["tmp_name"], $url);
    echo "Stored $filename in $url\n";
  }

  return ($url);
}

function getDBParentId($dbconn, $trip_id, $phone_parent_id)
{
  $query = "SELECT FROM media WHERE TRIP_ID = '".$trip_id."' AND PHONE_DB_ID='". $phone_parent_id ."'";
  $result = $dbconn->query($query);
  $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  return ($row['id']);
}

?>
